<?php
require_once dirname(__FILE__) . '/../includes/common.inc.php';
require_once dirname(__FILE__) . '/../includes/pdoorm.inc.php';

  $orderid = MiscUtils::getParam('cno', '');
  
 // function receipttopdf($orderid){
  	 
   $tmpaf = array();

   if(!empty($orderid))
   {
   	  $sql = "select * from ns_v1customer where e_oid =".$orderid." ";
   	  
   	  $cusinfo = getone($sql);
   	  
   	  $tmpaforders = array();
   	  
   	  $tmporder = getsonall('ns_v1myorder','customerId',$orderid);
   	  
      foreach($tmporder as $order)
   	  {
   	      $order->products = array();
          $pitem = getsonall('ns_v1purchaseitem','order_id',$order->e_oid);
          
          $order->products = $pitem;
          
          $order->payments = array();
          $payment = getsonall('ns_v1payment','orderId',$order->e_oid); 
          $order->payments = $payment;
          
          $sqlpaym="SELECT SUM(amount) AS amount,orderId,customerId,`date`,stage,cancelled FROM ns_v1payment WHERE orderId=".$order->e_oid." GROUP BY trackId,orderId";
          $paytmp=getall($sqlpaym);
          $order->pays = $paytmp;          
          
          $order->expense = array();
          
          $sqlex="SELECT * FROM ns_expense WHERE particular ='refund' AND refundNo = ".$order->e_oid." ";
          $extmp=getall($sqlex);
          $order->expense = $extmp;
          
          $tmpaforders[] = $order;
   	  }
   	  
   	  
   	  $tmpaf['bridename'] = $cusinfo->bridename;
   	  $tmpaf['bridephone'] = $cusinfo->bridephone;
   	  $tmpaf['bridemobile'] = $cusinfo->bridemobile;
   	  $tmpaf['brideemail'] = $cusinfo->brideemail;
   	  $tmpaf['brideaddrLn1'] = $cusinfo->brideaddrLn1;
   	  $tmpaf['brideaddrLn2'] = $cusinfo->brideaddrLn2;
   	  $tmpaf['brideaddrLn3'] = $cusinfo->brideaddrLn3;
   	  $tmpaf['brideaddrLn4'] = $cusinfo->brideaddrLn4;
   	  
   	  $tmpaf['groomname'] = $cusinfo->groomname;
   	  $tmpaf['groomphone'] = $cusinfo->groomphone;
   	  $tmpaf['groommobile'] = $cusinfo->groommobile;
   	  $tmpaf['groomemail'] = $cusinfo->groomemail;
   	  $tmpaf['groomaddrLn1'] = $cusinfo->groomaddrLn1;
   	  $tmpaf['groomaddrLn2'] = $cusinfo->groomaddrLn2;
   	  $tmpaf['groomaddrLn3'] = $cusinfo->groomaddrLn3;
   	  $tmpaf['groomaddrLn4'] = $cusinfo->groomaddrLn4;
   	  $tmpaf['customerid'] = $cusinfo->e_oid;
   	  
   	  $tmpaf['orders'] = $tmpaforders;
   	  
   	  
   }


$html ="<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">";
$html .="<html>";
$html .=" <head>";
$html .=" <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />";
$html .="  <title>Receipt</title>";
$html .=" </head>";
$html .=" <body >";
$html .="<div id=\"container\">";
$html .="  <table class=\"contract_table1\" cellPadding=\"0\" cellSpacing=\"0\">";
$html .="    <tr>";
$html .="      <td class=\"contract_td1\">";
$html .="        Customer No.";
$html .="      </td>";
   $cusno = BRANCH.customerno($orderid); 
$html .="      <td class=\"contract_td2\" id=\"customerno\">".$cusno."</td>";
$html .="    </tr>";
$html .="  </table>";
  
 $html .=" <table class=\"contract_table2\" cellPadding=\"0\" cellSpacing=\"0\">";
$html .="    <tr>";
 $html .="     <td>";
 $html .="       <img src=\"../images/common/line.png\"></img>";
$html .="      </td>";
 $html .="   </tr>";
 $html .=" </table>";
  
 $html .=" <table class=\"contract_table3\" cellPadding=\"0\" cellSpacing=\"0\">";
$html .="    <tr>";
$html .="<td class=\"contract_td3\">";
$html .="        Bride Name";
      $html .="</td>";
      $brindename = ($tmpaf['bridename']) ? $tmpaf['bridename'] : '';
$html .=" <td class=\"contract_td4\" id=\"bridename\">".$brindename."</td>";
$html .="      <td class=\"contract_td5\">";
$html .="        Groom Name";
$html .="      </td>";
$groomname = ($tmpaf['groomname']) ? $tmpaf['groomname'] : '';
$html .="      <td class=\"contract_td6\" id=\"groomname\">".$groomname."</td>";
$html .="    </tr>";
    
$html .="    <tr>";
$html .="      <td class=\"contract_td3\">";
$html .="       Address";
 $html .="     </td>";
 $bridead1 = ($tmpaf['brideaddrLn1']) ? $tmpaf['brideaddrLn1'] : '';
$html .="      <td class=\"contract_td4\" id=\"bridead1\">".$bridead1."</td>";
 $html .="     <td class=\"contract_td5\">";
$html .="       Address";
$html .="      </td>";
       $groomad1 = ($tmpaf['groomaddrLn1']) ? $tmpaf['groomaddrLn1'] : '';
$html .="      <td class=\"contract_td6\" id=\"groomad1\">".$groomad1."</td>";
 $html .="   </tr>";
    
$html .="    <tr>";
$html .="      <td class=\"contract_td3\">&nbsp;</td>";
$bridead2 = ($tmpaf['brideaddrLn2']) ? $tmpaf['brideaddrLn2'] : '';
$html .="      <td class=\"contract_td4\" id=\"bridead2\">".$bridead2."</td>";
 $html .="     <td class=\"contract_td5\">&nbsp;</td>";
 $groomad2 = ($tmpaf['groomaddrLn2']) ? $tmpaf['groomaddrLn2'] : '';
$html .="      <td class=\"contract_td6\" id=\"groomad2\">".$groomad2."</td>";
$html .="    </tr>";

$html .="    <tr>";
$html .="      <td class=\"contract_td3\">";
 $html .="       Phone";
$html .="     </td>";
$bridephone = ($tmpaf['bridephone']) ? $tmpaf['bridephone'] : '';
 $html .="     <td class=\"contract_td4\" id=\"bridephone\">".$bridephone."</td>";
$html .="      <td class=\"contract_td5\">";
 $html .="       Phone";
$html .="      </td>";
$groomphone = ($tmpaf['groomphone']) ? $tmpaf['groomphone'] : '';
$html .="      <td class=\"contract_td6\" id=\"groomphone\">".$groomphone."</td>";
 $html .="   </tr>";
    
$html .="    <tr>";
 $html .="     <td class=\"contract_td3\">";
 $html .="       Mobile";
 $html .="     </td>";
 $bridemobile = ($tmpaf['bridemobile']) ? $tmpaf['bridemobile'] : '';
 $html .="     <td class=\"contract_td4\" id=\"bridemobile\">".$bridemobile."</td>";
 $html .="     <td class=\"contract_td5\">";
 $html .="       Mobile";
$html .="      </td>";
$groommobile = ($tmpaf['groommobile']) ? $tmpaf['groommobile'] : '';
 $html .="     <td class=\"contract_td6\" id=\"groommobile\">".$groommobile."</td>";
 $html .="   </tr>";
$html .="    <tr>";
$html .="      <td class=\"contract_td3\">";
$html .="        Email";
$html .="      </td>";
$brideemail = ($tmpaf['brideemail']) ? $tmpaf['brideemail'] : '';
$html .="      <td class=\"contract_td4\" id=\"brideemail\">".$brideemail."</td>";
$html .="      <td class=\"contract_td5\">";
$html .="        Email";
$html .="      </td>";
$groomemail = ($tmpaf['groomemail']) ? $tmpaf['groomemail'] : '';
$html .="      <td class=\"contract_td6\" id=\"groomemail\">".$groomemail."</td>";
$html .="    </tr>";
$html .="  </table>";
  
$html .="  <table class=\"contract_table2\" cellPadding=\"0\" cellSpacing=\"0\">";
$html .="    <tr>";
$html .="      <td>";
$html .="        <img src=\"../images/common/line.png\"></img>";
$html .="      </td>";
$html .="    </tr>";
$html .="  </table>";

$orders = $tmpaf['orders'];

$tprice = 0; //总应该收
$tpay   = 0; //已经收
$tex    = 0; //已退

if(!empty($orders)){
	foreach ($orders as $ors){
		 if($ors->disposalstatus == 1) continue;
		
         $tprice+= $ors->price;

         //已经收款
         $mpay = $ors->payments;
         if(!empty($mpay)){
         	foreach($mpay as $mp){
         		if($mp->cancelled == 1) continue;
         		   $tpay +=$mp->amount;
         	}
         }
         
         //退款
         $exp = $ors->expense;
         if(!empty($exp)){
         	foreach ($exp as $eo){
         	    if($eo->status == '-1') continue;
         	       $tex +=$eo->amount;
         	}
         }
         
	}
}

$ytpay = $tpay - $tex;//已经收减去已经退
$cpay = $tprice*(1+ GST) - $ytpay;//还没有收的


$tprice = $tprice > 0 ? '$'.sprintf("%.2f",$tprice*(1+ GST)).'(Inc.'. TAX .')' : '$0.00';
$ytpay = '$'.sprintf("%.2f",$ytpay);
$cpay =  '$'.sprintf("%.2f",$cpay);


        //总的payment和price
	        $html .="  <table class=\"contract_table9\" cellPadding=\"0\" cellSpacing=\"0\">";
			$html .="    <tr>";
			$html .="      <td id=\"contract_orderInfo_div\" align=\"center\">";
			$html .="      <table width=\"100%\" class=\"pl15\" border=0>";
			$html .="         <tr>";
			$html .="            <td id='otype' class=\"contract_td3  f140\" colspan='4'>Payment </td>";
			$html .="         </tr>";
			
			$html .="         <tr style=\"height:30px;\">";
			$html .="            <td class=\"contract_td3 f120\" colspan='4'>";
			$html .="               <table class='pagereceipt_table6' cellspacing=\"0\" cellpadding=\"0\">";
			$html .="                 <tr>";
			$html .="                     <td class='pagereceipt_td8'>Total Price </td>";
			$html .="                     <td class='pagereceipt_td10'>".$tprice."</td>";
			$html .="                     <td class='pagereceipt_td8'>Total Received  </td>";
			$html .="                     <td class='pagereceipt_td10'>".$ytpay."</td>";
			$html .="                     <td class='pagereceipt_td8'>Total Anticipated </td>";
			$html .="                     <td class='pagereceipt_td10'>".$cpay."</td>";			
			
			$html .="                 </tr>";
			$html .="               </table>";
			$html .="         </td>";
			$html .="         </tr>";

			$html .="      </table>";
			        
			$html .="      </td>";
			$html .="    </tr>";
			$html .="  </table>";	  

			
			
$html .="  <table class=\"contract_table2\" cellPadding=\"0\" cellSpacing=\"0\">";
$html .="    <tr>";
$html .="      <td>";
$html .="        <img src=\"../images/common/line.png\"></img>";
$html .="      </td>";
$html .="    </tr>";
$html .="  </table>";	 




if(!empty($orders)){
	
	  foreach($orders as $onp){
	  	  $prs = $onp->products;
	  	  
	  	  $palbum ='';
	  	  $valbum ='';
	  	  $aalbum ='';
	  	  
	  	  if(!empty($prs)){
	  	  	foreach($prs as $ops){
	  	  		if($ops->canlled == 1) continue;
	  	  		
	  	  		//摄影套餐的相册
	  	  		if($ops->packageInc == PACKAGE_TYPE_PHOTO && $ops->type == SAMPLE_TYPE_ALBUM){
	  	  			$palbum .=$ops->name .'&nbsp;&nbsp;&nbsp;&nbsp;';
	  	  		}
	  	  		
	  	  		//摄像套餐的DVD
	  	  		if($ops->packageInc == PACKAGE_TYPE_VIDEO && ($ops->model == MODEL_NAME_PRODUCT_VIDEODVD  ||$ops->model == MODEL_NAME_PRODUCT_VIDEODVD_BLURAY) ){
	  	  			$valbum .=$ops->name .'&nbsp;&nbsp;&nbsp;&nbsp;';
	  	  		}

	  	  		//addition里面的相册 
	  	  		if($ops->packageInc == '' && $ops->type == SAMPLE_TYPE_ALBUM){
	  	  			$aalbum .=$ops->name .'&nbsp;&nbsp;&nbsp;&nbsp;';
	  	  		}	  	  		
	  	  		
	  	  	}
	  	  }
	  	  
	  	  /*客人的payment总计*/
	  	  $otprice = 0 ;
	  	  $otpay   = 0 ;
	  	  $otex    = 0 ;
	  	  
	  		 if($ors->disposalstatus == 1) continue;
		
	         $otprice= $onp->price;
	
	         //已经收款
	         $mpayo = $onp->payments;
	         $sumrec = 0;$stage = 0;$itotal1 = 0;$itotal2 = 0;$itotal3 = 0;$itotal4 = 0;
	         if(!empty($mpayo)){
	         	foreach($mpayo as $mpo){
	         		if($mpo->cancelled == 1 || $mpo->orderId != $onp->e_oid) continue;
	         		   $otpay +=$mpo->amount;
	         		   
	         		   if ($mpo->stage == 1) $itotal1 += $mpo->amount;
	                   if ($mpo->stage == 2) $itotal2 += $mpo->amount;
	                   if ($mpo->stage == 3) $itotal3 += $mpo->amount;
	                   if ($mpo->stage == 4) $itotal4 += $mpo->amount;
	                   
	                   $stage = max($stage, $mpo->stage);
	         	}
	         }
	         
	         //退款
	         $expo = $onp->expense;
	         if(!empty($expo)){
	         	foreach ($expo as $eoo){
	         	    if($eoo->status == '-1' || $eoo->refundNo != $onp->e_oid) continue;
	         	       $otex +=$eoo->amount;
	         	}
	         }
	  	
$oytpay = $otpay - $otex;//已经收减去已经退
$ocpay = $otprice*(1+ GST) - $oytpay;//还没有收的


$otprice = $otprice > 0 ? '$'.sprintf("%.2f",$otprice*(1+ GST)).'(Inc.'. TAX .')' : '$0.00';
$oytpay = '$'.sprintf("%.2f",$oytpay);
$ocpay =  '$'.sprintf("%.2f",$ocpay);
	         
	  	
	        $html .="  <table class=\"contract_table9\" cellPadding=\"0\" cellSpacing=\"0\" border=0>";
			$html .="    <tr>";
			$html .="      <td id=\"contract_orderInfo_div\" align=\"center\">";
					$html .="      <table width=\"100%\" class=\"pl15\" border=0>";
					
					$html .="         <tr>";
					$html .="            <td id='otype' class=\"contract_td3  f140\" colspan='4'>".$onp->type.'&nbsp;&nbsp;&nbsp;'."<span style=\"font-size: 13px;color:#000000;font-weight:normal; margin: 0px 0px 0px 10px;\">".SimpleDate::toUTC($onp->date)."</span></td>";
					$html .="         </tr>";
		
					$html .="         <tr>";
					$html .="            <td id='otype' class=\"contract_td300  \" colspan='4'>Type of coverage selected Photograhpy:   <u>".$onp->photoname."</u>    Album: <u>".$palbum."</u></td>";
					$html .="         </tr>";
		
					$html .="         <tr>";
					$html .="            <td id='otype' class=\"contract_td300  \" colspan='4'>Type of coverage selected Videograhpy:   <u>".$onp->videoname." </u>   Video: <u>".$valbum."</u>    </td>";
					$html .="         </tr>";
		
					$aalbumstr = !empty($aalbum) ? "Additions:<u>".$aalbum."</u>" : '';
					
					$html .="         <tr>";
					$html .="            <td id='otype' class=\"contract_td300 \" colspan='4'>".$aalbumstr."</td>";
					$html .="         </tr>";			
					
					$html .="         <tr style=\"height:30px;\">";
					$html .="            <td class=\"contract_td3 f120\" colspan='4' width=\"100%\">";
					$html .="               <table class='pagereceipt_table61' style=\"width: 100%;\" cellspacing=\"0\" cellpadding=\"0\" border=0>";
					$html .="                 <tr>";
					$html .="                     <td class='pagereceipt_td8'>SUB-Total Price </td>";
					$html .="                     <td class='pagereceipt_td10'>".$otprice."</td>";
					$html .="                     <td class='pagereceipt_td8'>SUB-Total Received  </td>";
					$html .="                     <td class='pagereceipt_td10'>".$oytpay."</td>";
					$html .="                     <td class='pagereceipt_td8'>SUB-Total Anticipated </td>";
					$html .="                     <td class='pagereceipt_td10'>".$ocpay."</td>";			
					$html .="                 </tr>";
					$html .="               </table>";
					$html .="           </td>";
					$html .="         </tr>";
					
					
		
					$html .="         <tr style=\"height:30px;\">";
					$html .="            <td class=\"contract_td3 f120\" colspan='4'>";
					$html .="               <table style=\"width: 100%;\" cellspacing=\"0\" cellpadding=\"0\" border=0>";
					$html .="                 <tr>";
						$html .="               <td align=\"center\" style=\"width: 960px; height: 30px; vertical-align: middle;\">";
								$html .="               <table cellspacing=\"0\" cellpadding=\"0\" style=\"width: 560px;\">";
									$html .="               <tbody>";
										$html .="               <tr>";
										    $html .="               <td>&nbsp;</td>";
										    $html .="               <td align=\"center\" style=\"width: 160px; font-weight: bold; padding-left: 140px; font-size: 110%; color: rgb(102, 51, 51); white-space: nowrap; vertical-align: middle;\">&nbsp;</td>";
										    $html .="               <td align=\"left\" style=\"font-weight: bold; padding-left: 190px; color: rgb(102, 51, 51); vertical-align: middle;\">System Calculate</td>";
										    $html .="               <td align=\"left\" style=\"font-weight: bold; padding-right: 4px; color: rgb(102, 51, 51); vertical-align: middle;\">Actual Residue</td>";
										$html .="               </tr>";
									$html .="               </tbody>";
								$html .="               </table>";
						$html .="               </td>";
						$html .="               <td align=\"left\" style=\"width: 528px; color: rgb(102, 51, 51); vertical-align: middle; height: 30px; font-weight: bold;\">Actual Paid</td>";
					$html .="                 </tr>";
					
	      	 $rule =  payment($onp->type);
	
	    	 for($i = 1, $j = count($rule); $i <= $j;$i++)
	    	 {
	    	 	$ru = $rule[$i-1];
	    	 	
	    	 	if($i == 1){
	    	 		  $ptitle = 'Deposit(Non-Refundable)';
	    	 		  $itotal = $itotal1;
	    	 	}else{
	    	 		if($i == 2) {
	    	 			$pt = 'nd';
	    	 			$itotal = $itotal2;
	    	 		}
	    	 		if($i == 3) {
	    	 			$pt = 'rd';
	    	 			$itotal = $itotal3;
	    	 		}
	    	 		if($i == 4) {
	    	 			$pt = 'th';
	    	 			$itotal = $itotal4;
	    	 		}
	    	 		
	    	 		$ptitle = $i."<sup>$pt</sup>" .'  payment';
	    	 	}
	    	 	
	    	 	
	    	 	 $syscaln = sprintf("%.2f",$onp->price* $ru['rate']);
	    	 	 $syscal = sprintf("%.2f",$onp->price*(1+ GST)* $ru['perc']);
		         $nopay = sprintf("%.2f",$syscal - $itotal) ;
		         $sumynopay = sprintf("%.2f",$syscaln-$otpay);
		 
		         $nop =  $sumynopay > 0 ? $nopay : '0.00'; 
	    	 	
	    	 	//$price1 = sprintf("%.2f",$onp->price*(1+ GST)).'(Inc.'. TAX .')';
	    	 	$price1 = sprintf("%.2f",$onp->price*(1+ GST));
	    	 	$tpr = sprintf("%.2f",$price1* $ru['perc']).'(Inc.'. TAX .')  '.strtolower($ru['comment']);
	    	 	
	    	 	
	    	 	$gpay = $onp->pays;
	    	 	
	    	 	$phtml ='';
	    	 	
	    	 	if(!empty($gpay)){
	    	 		$phtml ='<table>';
	    	 		
	    	 		foreach($gpay as $gop){
	    	 			if($gop->stage != $i || $gop->cancelled == 1) continue;
	    	 			    $phtml .="<tr>";
	    	 			         $phtml .="<td>$".$gop->amount."</td>";
	    	 			         $phtml .="<td>paid on</td>";
	    	 			         $phtml .="<td>".SimpleDate::toUTC($gop->date)."</td>";
	    	 			    $phtml .="</tr>";
	    	 		}
	    	 		
	    	 		$phtml .='</table>';
	    	 	}
	    	 	
	    	 	$gref = $onp->expense;
	    	 	
	    	 	$rhtml ='';
	    	 	$rtotal =0;
	    	 	
	    	 	if(!empty($gref)){
	    	 		$rhtml ='<table>';
	    	 		
	    	 		foreach($gref as $rop){
                        
	    	 			if($rop->status == '-1' || $rop->refundNo != $onp->e_oid) continue;
	    	 			  $rtotal += $rop->amount;
	    	 			    $rhtml .="<tr>";
	    	 			         $rhtml .="<td>$".$rop->amount."</td>";
	    	 			         $rhtml .="<td>paid on</td>";
	    	 			         $rhtml .="<td>".SimpleDate::toUTC(SimpleDate::fromStamp($rop->payDate))."</td>";
	    	 			    $rhtml .="</tr>";
	    	 		}
	    	 		
	    	 		$rhtml .='</table>';
	    	 	}
	    	 	
	    	 	
	    	 	
	    	 	
					$html .="                 <tr>";
						$html .="               <td align=\"center\" style=\"width: 960px; height: 30px; vertical-align: middle;\">";
								$html .="               <table cellspacing=\"0\" cellpadding=\"0\" style=\"width: 560px;\" border=0>";
									$html .="               <tbody>";
										$html .="               <tr>";
										    $html .="               <td width='300px' align='right'>".$ptitle."</td>";
										    $html .="               <td align=\"left\" style=\"width: 160px;padding-left: 40px; font-weight: bold;  font-size: 110%; color: rgb(102, 51, 51); white-space: nowrap; vertical-align: middle;\">$".$syscal."(inc.GST)".$ru['title']."</td>";
										    $html .="               <td align=\"left\" style=\"font-weight: bold; padding-left: 60px; color: rgb(102, 51, 51); vertical-align: middle;\">$".$nop."(inc.GST)</td>";
										    $html .="               <td align=\"left\" style=\"font-weight: bold; padding-right: 4px; color: rgb(102, 51, 51); vertical-align: middle;\"></td>";
										$html .="               </tr>";
									$html .="               </tbody>";
								$html .="               </table>";
						$html .="               </td>";
						$html .="               <td align=\"left\" style=\"width: 528px; color: rgb(102, 51, 51); vertical-align: middle; height: 30px; font-weight: bold;\">".$phtml."</td>";
					$html .="                 </tr>";

	 		       		 
	    	
	    if($i==$j){	 //循环最后一次就加入next due和refund	
	    					
	  	  if ($rule[$stage]) {
		      $due = sprintf("%.2f",$onp->price*(1+ GST)*$rule[$stage]['rate'] - $otpay + $rtotal);
	      } else {
	    	  $due = sprintf("%.2f",$onp->price*(1+ GST) - $otpay + $rtotal);
	      }
					//************************next payment*******************************
					$html .="                 <tr>";
						$html .="               <td align=\"center\" style=\"width: 960px; height: 30px; vertical-align: middle;\">";
								$html .="               <table cellspacing=\"0\" cellpadding=\"0\" style=\"width: 560px;\" border=0>";
									$html .="               <tbody>";
										$html .="               <tr>";
										    $html .="               <td width='120px' align='right'>&nbsp;</td>";
										    $html .="               <td align=\"right\" style=\"width: 297px;padding-right:-14px; font-weight: bold;  font-size: 110%; color: rgb(102, 51, 51); white-space: nowrap; vertical-align: middle;\">Your next payment due:</td>";
										    $html .="               <td align=\"left\" style=\"font-weight: bold;padding-left: 15px;  color: rgb(102, 51, 51); vertical-align: middle;\">$".$due."(inc.GST)</td>";
										    $html .="               <td align=\"left\" style=\"font-weight: bold;padding-right: 4px; color: rgb(102, 51, 51); vertical-align: middle;\">&nbsp;</td>";
										$html .="               </tr>";
									$html .="               </tbody>";
								$html .="               </table>";
						$html .="               </td>";
						$html .="               <td align=\"left\" style=\"width: 528px; color: rgb(102, 51, 51); vertical-align: middle; height: 30px; font-weight: bold;\"></td>";
					$html .="                 </tr>";
					//************************next payment*******************************	

					 
					//************************refund*******************************
					$html .="                 <tr>";
						$html .="               <td align=\"center\" style=\"width: 960px; height: 30px; vertical-align: middle;\">";
								$html .="               <table cellspacing=\"0\" cellpadding=\"0\" style=\"width: 560px;\" border=0>";
									$html .="               <tbody>";
										$html .="               <tr>";
										    $html .="               <td width='120px' align='right'>&nbsp;</td>";
										    $html .="               <td align=\"right\" style=\"width:185px;padding-right: 35px; font-weight: bold;  font-size: 110%; color: rgb(102, 51, 51); white-space: nowrap; vertical-align: middle;\">Refund:</td>";
										    $html .="               <td align=\"left\" style=\"font-weight: bold; padding-left: 105px; color: rgb(102, 51, 51); vertical-align: middle;\">".$rhtml."</td>";
										    $html .="               <td align=\"left\" style=\"font-weight: bold; padding-right: 4px; color: rgb(102, 51, 51); vertical-align: middle;\">&nbsp;</td>";
										$html .="               </tr>";
									$html .="               </tbody>";
								$html .="               </table>";
						$html .="               </td>";
						$html .="               <td align=\"left\" style=\"width: 528px; color: rgb(102, 51, 51); vertical-align: middle; height: 30px; font-weight: bold;\"></td>";
					$html .="                 </tr>";	
                         //************************refund*******************************			
	        }
		}	
					$html .="               </table>";
					$html .="         </td>";
					$html .="         </tr>";

					
					
					$html .="      </table>";
			        
			$html .="      </td>";
			$html .="    </tr>";
			$html .="  </table>";	 	  	

	  }
	  
 
	
}else{
	        $html .="  <table class=\"contract_table9\" cellPadding=\"0\" cellSpacing=\"0\">";
			$html .="    <tr>";
			$html .="      <td id=\"contract_orderInfo_div\" align=\"center\">";
			$html .="      <table width=\"100%\" class=\"pl15\" border=0>";
			$html .="         <tr>";
			$html .="            <td id='otype' class=\"contract_td3  f140\" colspan='4'>Payment </td>";
			$html .="         </tr>";
			
			$html .="         <tr style=\"height:30px;\">";
			$html .="            <td class=\"contract_td3 f120\" colspan='4'>";
			$html .="               <table class='pagereceipt_table6' cellspacing=\"0\" cellpadding=\"0\">";
			$html .="                 <tr>";
			$html .="                     <td class='pagereceipt_td8'>Total Price </td>";
			$html .="                     <td class='pagereceipt_td10'>$0.00</td>";
			$html .="                     <td class='pagereceipt_td8'>Total Received  </td>";
			$html .="                     <td class='pagereceipt_td10'>$0.00</td>";
			$html .="                     <td class='pagereceipt_td8'>Total Anticipated </td>";
			$html .="                     <td class='pagereceipt_td10'>$0.00</td>";			
			
			$html .="                 </tr>";
			$html .="               </table>";
			$html .="         </td>";
			$html .="         </tr>";

			$html .="      </table>";
			        
			$html .="      </td>";
			$html .="    </tr>";
			$html .="  </table>";	 
}
  
$html .="  <table class=\"contract_table2\" cellPadding=\"0\" cellSpacing=\"0\">";
$html .="    <tr>";
$html .="      <td>";
$html .="        <img src=\"../images/common/line.png\"></img>";
$html .="      </td>";
$html .="    </tr>";
$html .="  </table>";
  
if(!empty($orders))
{  $contract = $orders[0]->contract[0];
	$html .="  <table class=\"contract_table8\" cellPadding=\"0\" cellSpacing=\"0\">";
	$html .="    <tr>";
	$html .="      <td class=\"contract_td24\" id=\"contract_list_div\">".nl2br($contract->content)."</td>";
	$html .="    </tr>";
	$html .="  </table>";
}else{
	$html .="  <table class=\"contract_table8\" cellPadding=\"0\" cellSpacing=\"0\">";
	$html .="    <tr>";
	$html .="      <td class=\"contract_td24\" id=\"contract_list_div\"></td>";
	$html .="    </tr>";
	$html .="  </table>";	
}


$html .="</div>";
$html .=" </body>";
$html .="</html>";

//==============================================================
//==============================================================
//==============================================================


include dirname(__FILE__)."/../library/MPDF56/mpdf.php";


$dest_dir = dirname(__FILE__)."/files/".$orderid; 
if(!is_dir($dest_dir)) mkdir($dest_dir,0777); 
$filename = 'receipt'.date("YmdHis").'-'.$orderid.'.pdf';
$aa=$dest_dir.'/'.$filename;



$mpdf=new mPDF(); 

// LOAD a stylesheet
$stylesheet = file_get_contents('bookform.css');
$mpdf->WriteHTML($stylesheet,1);	// The parameter 1 tells that this is css/style only and no body/html/text

$mpdf->WriteHTML($html);

//$mpdf->Output();
$mpdf->Output($aa);
echo $filename;
exit;
  //return $filename;
//}



//==============================================================
//==============================================================
//==============================================================


?>